package com.app.controller;

import com.app.utils.ShiroUtil;
import com.app.view.TreeMenu;
import com.core.aspect.Log;
import com.sys.menu.entity.SysMenu;
import com.sys.menu.service.SysMenuService;
import com.sys.user.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 首页控制器
 *
 * @author djianfeng
 * @date 2018年8月16日13:47:47
 */
@Controller
@RequestMapping("/")
public class IndexController {
    @Autowired
    SysMenuService menuService;

    @Log("进入首页")
    @RequestMapping({"index.do"})
    public String index(Model model) {
        SysUser me = ShiroUtil.getSessionUser();
        List<TreeMenu> treeMenus = menuService.selectTreeMenuByUserId(me.getId());
        model.addAttribute("treeMenus", treeMenus);
        model.addAttribute("me", me);
        return "index";
    }

    @Log("进入欢迎页")
    @RequestMapping({"/welcome.do"})
    public String welcome() {
        return "welcome";
    }

    @Log("进入登录页")
    @RequestMapping({"", "/"})
    public String index() {
        return "login";
    }

    @Log("添加用户")
    @RequiresPermissions("addUser")
    @RequestMapping("/add")
    public String add(Model model) {
        return "index";
    }

    @Log("查询菜单")
    @RequestMapping("forward.do")
    public String forward(Model model, String url, Long pid, Long id) {
        SysMenu pmenu = menuService.selectById(pid);
        SysMenu menu = menuService.selectById(id);
        model.addAttribute("menu", menu);
        model.addAttribute("pmenu", pmenu);
        return "forward:" + url;
    }

}
